Skip to content

feat: config export/import + MCP notification monitor - #37

Merged
ourines merged 14 commits into
mainfrom
feat/config-export
Feb 15, 2026
Merged

feat: config export/import + MCP notification monitor#37
ourines merged 14 commits into
mainfrom
feat/config-export

Conversation

@ourines

@ourines ourines commented Feb 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • Config export/import: codes config export / codes config import for sharing config between machines. Sensitive values (TOKEN, KEY, SECRET, PASSWORD) auto-redacted on export, skipped on import.
  • MCP notification monitor: Replace client-dependent MonitorCmd bash scripts with server-side singleton goroutine. Notifications are piggybacked on agent tool responses and team_watch is recommended for real-time monitoring.

Changes

Config export/import

  • internal/commands/cobra.go — Register ConfigExportCmd and ConfigImportCmd
  • internal/commands/config_sync.goRunConfigExport / RunConfigImport implementation

MCP notification monitor

  • internal/mcp/monitor.go — Singleton goroutine polling ~/.codes/notifications/, pending queue (cap 100), best-effort MCP logging push
  • internal/mcp/agent_tools.go — Remove MonitorCmd, add MonitorActive + Notifications piggyback to 7 handlers, update tool descriptions with polling + team_watch recommendations
  • internal/mcp/monitor_e2e_test.go — 5 Go e2e tests + full MCP protocol e2e test (27 assertions)

Test plan

  • go build ./... passes
  • go vet ./... clean
  • go test ./... all pass (including 5 new MCP e2e tests)
  • Full MCP protocol e2e test (27/27 assertions pass): team create → agent add → task create → notification piggyback → drain idempotency → team_watch fallback

Summary by CodeRabbit

  • New Features

    • Added system diagnostics command for health checks including CLI, configuration, API connectivity, and disk space.
    • Added webhook notification management with add, remove, list, and test operations.
    • Added configuration import/export functionality with sensitive data redaction.
    • Added project linking capabilities in the UI.
    • Added workflow approval system with auto-approval and retry support.
    • Added workflow run history persistence.
    • Added agent daemon supervision with auto-restart and health monitoring.
    • Added terminal session support for FreeBSD and OpenBSD platforms.
  • Improvements

    • Configuration file permissions now enforced to 0600 for enhanced security.
    • API connection tests now display latency measurements.

Implement minimum viable version of secure token storage:
- Add checkConfigPermissions() to verify file is not world-readable (0600)
- LoadConfig() warns if config has insecure permissions (backward compatible)
- SaveConfig() sets 0600 permissions and verifies them
- Add comprehensive unit tests for permission checks

Relates to #10
Phase 1: Config layer (internal/config/)
- UnmarshalJSON migration logic (old flat format → new env map)
- TestAPIConfig response handling (200, 400, 401, 500, timeout)
- ShouldSkipPermissions priority logic
- GetDefaultBehavior validation and fallback
- LoadConfig / SaveConfig round-trip
- ProjectEntry serialization (string vs object format)
- RemoteHost UserAtHost formatting

Coverage: 37.4% of config package statements

Tests verify backward compatibility, API connectivity,
configuration priority resolution, and file I/O operations.

Related to #11 (Phase 2 and 3 will be completed in separate PRs)
实现 #26 - 添加TUI表单管理项目上下文链接

新增功能���
1. Projects detail panel 添加 'l' 快捷键入口
2. Link 添加表单:选择目标项目、设置 role
3. 支持 unlink 操作
4. 显示已链接项目列表

主要修改:
- internal/tui/linkform.go: 新增链接管理表单组件
- internal/tui/model.go: 添加 viewLinkForm 状态和相关处理
- internal/tui/projects.go: 更新帮助文本显示 'l' 快捷键

用户体验:
- 在项目列表中按 'l' 打开链接管理
- 列表模式:查看已有链接,按 'a' 添加,按 'd' 删除
- 添加模式:选择项目,可选填 role 描述
- 删除模式:确认删除链接
- Add WebhookConfig struct to Config (URL, format, events filter)
- Implement webhook management: add/remove/list/test commands
- Integrate webhooks into agent daemon notification system
- Support Slack and Feishu webhook formats
- Event-based filtering (task_completed, task_failed)

Closes #27
Implements comprehensive system diagnostics:
- Claude CLI installation and version check
- Configuration file validation
- API connectivity test
- File permissions verification
- Agent daemon status monitoring
- Disk space analysis

Closes #34
Extend Linux terminal detection to FreeBSD and OpenBSD since they
share similar terminal emulators (xterm, konsole, gnome-terminal).

Closes #33
Create terminal_freebsd.go and terminal_openbsd.go with platform-specific
build tags, copying the Linux terminal emulator detection logic since these
BSDs share similar terminal environments (xterm, konsole, gnome-terminal).

Revert terminal_linux.go to linux-only to ensure proper build constraint
resolution across all platforms.

Closes #33
Display round-trip latency in milliseconds for API connection tests,
both in single-config and all-configs modes.

Closes #17
Replace client-dependent MonitorCmd with an in-process singleton
goroutine that polls ~/.codes/notifications/ and delivers task
completion/failure notifications via piggyback on agent tool responses.

- Add internal/mcp/monitor.go with ensureMonitorRunning singleton
- All notifications reliably queued in pending buffer (cap 100)
- MCP ServerSession.Log used as best-effort push (SetLevel caveat)
- task_create/agent_start/team_start_all auto-start the monitor
- Query handlers (task_list/task_get/team_status/agent_list) drain
  pending notifications into responses
- Tool descriptions recommend team_watch + periodic team_status
  for real-time and polling-based monitoring
- Add e2e tests covering full MCP protocol notification flow
Add `codes config export` and `codes config import` for sharing
configuration between machines. Sensitive values (TOKEN, KEY, SECRET,
PASSWORD) are automatically redacted on export and skipped on import.
@ourines
ourines merged this pull request into main Feb 15, 2026
1 of 3 checks passed
@coderabbitai

coderabbitai Bot commented Feb 15, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR introduces multiple interconnected features: a system diagnostics command, webhook notifications for task events, daemon supervision with auto-restart and health monitoring, workflow approval prompts with persistence, config import/export with sensitive value redaction, TUI project linking, FreeBSD/OpenBSD terminal support, and MCP notification monitoring with response piggybacking.

Changes

Cohort / File(s) Summary
Doctor Diagnostics
CLAUDE.md, docs/doctor.md, cmd/codes/main.go, internal/commands/cobra.go, internal/commands/doctor.go
New doctor subcommand performs six sequential system checks: CLI installation, config loading, API connectivity, file permissions, agent daemon status, and disk space; exits with code 1 on failure.
Webhook Notifications
internal/agent/daemon.go, internal/config/config.go, internal/commands/notify_cobra.go, internal/commands/notify_commands.go
Adds webhook notification system: new WebhookConfig type with CRUD operations (add, remove, list, test); daemon integrates sendWebhookNotifications to dispatch task completion/failure events to configured webhooks.
Configuration Management
internal/commands/config_sync.go, internal/config/config_test.go, internal/commands/commands.go
Introduces config import/export with redaction of sensitive values; adds config permission validation (0600); enhances API test output with latency measurements.
Daemon Supervision & State
internal/agent/supervisor.go, internal/agent/types.go
New Supervisor subsystem manages daemon lifecycle with auto-restart, exponential backoff, crash tracking, and health checks; extends AgentState with restart count, last crash timestamp, and supervision flag.
Workflow Approval & Persistence
internal/workflow/approval.go, internal/workflow/persistence.go, internal/workflow/runner.go, internal/workflow/types.go, internal/commands/workflow_commands.go
Adds approval workflow interface with CLI and auto-approval implementations; introduces workflow run persistence and lifecycle tracking (ID, timestamps, status); refactors RunWorkflow to accept options struct with retry support.
MCP Notification Monitoring
internal/mcp/monitor.go, internal/mcp/agent_tools.go, internal/mcp/monitor_e2e_test.go, internal/mcp/workflow_tools.go
Background monitor scans for notification files, buffers pending notifications with cap, and piggybacks them onto MCP responses; updates tool outputs to include monitor status and notifications; adds comprehensive E2E tests.
TUI Project Linking
internal/tui/linkform.go, internal/tui/model.go, internal/tui/projects.go
New link management form for projects with add/unlink flows; integrates into TUI state machine; updates keyboard bindings to expose link functionality.
Terminal Session Support
internal/session/terminal_freebsd.go, internal/session/terminal_openbsd.go, internal/session/terminal_other.go
Adds FreeBSD and OpenBSD-specific terminal launchers with emulator registry; refactors build constraints to gate terminal support on non-BSD platforms.

Sequence Diagram(s)

sequenceDiagram
    participant Daemon as Agent Daemon
    participant Task as Task Completion
    participant Notifier as Webhook Notifier
    participant Webhook as Webhook Server
    
    Daemon->>Task: Task status change (completed/failed)
    Daemon->>Daemon: sendWebhookNotifications(status, task)
    Daemon->>Notifier: Determine event type & filter webhooks
    Notifier->>Notifier: Build notification payload
    Notifier->>Webhook: POST notification to configured webhook
    Webhook-->>Notifier: Response
    Notifier->>Daemon: Log result (error non-blocking)
Loading
sequenceDiagram
    participant FS as File System (.codes/notifications)
    participant Monitor as Background Monitor
    participant Buffer as Pending Queue
    participant Response as MCP Response Handler
    
    FS->>Monitor: Notification files written
    Monitor->>Monitor: Poll directory periodically
    Monitor->>FS: Read & parse JSON notification files
    Monitor->>Buffer: Enqueue pending notifications
    Monitor->>FS: Clean up processed files
    Response->>Buffer: drainPendingNotifications()
    Buffer-->>Response: Return & clear buffered notifications
    Response->>Response: Piggyback onto response payload
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • PR #2: Modifies CLI command registration in cobra.go and cmd/codes/main.go; related through shared command wiring pattern for new subcommands.
  • PR #23: Introduces MCP server and session manager modifications; related through overlapping changes to internal/mcp/ and internal/session/ subsystems.

Poem

🐰 bounces excitedly
A doctor checks the system, webhooks send their call,
Daemons find supervisors keeping watch o'er all,
Workflows seek approval while projects link as friends,
Notifications piggyback... this PR ascends! 🚀

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/config-export

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

ourines added a commit that referenced this pull request Feb 15, 2026
feat: config export/import + MCP notification monitor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant